<?php
include '../Module/CommentModule.php';
$CmModule=new CommentModule();
if(isset($_REQUEST["action"])){
    switch ($_REQUEST["action"]){
        case"add":
            $_type		=isset($_REQUEST["_type"])?$_REQUEST["_type"]:"";
            $name		=isset($_REQUEST["name"])?EndcodeStr($_REQUEST["name"]):"";
            $comment		=isset($_REQUEST["comment"])?EndcodeStr($_REQUEST["comment"]):"";
            $acc		=isset($_REQUEST["acc"])?EndcodeStr($_REQUEST["acc"]):"";
            $rate		=isset($_REQUEST["rate"])?EndcodeStr($_REQUEST["rate"]):"";
            $parent		=isset($_REQUEST["parent"])?EndcodeStr($_REQUEST["parent"]):"";
            $cmfor		=isset($_REQUEST["cmfor"])?EndcodeStr($_REQUEST["cmfor"]):"";
            if($CmModule->insertComment($_type,$name,$comment,$rate,$parent,$cmfor)){
                echo "true";
            }else{
                echo "Error: Please, Check level of category.<br/>".$CmModule->error;
            }
            break;
        case"edit":
            $_type		=isset($_REQUEST["_type"])?$_REQUEST["_type"]:"";
            $id                 =isset($_REQUEST["id"])?$_REQUEST["id"]:"";
            $name		=isset($_REQUEST["name"])?EndcodeStr($_REQUEST["name"]):"";
            $comment		=isset($_REQUEST["comment"])?EndcodeStr($_REQUEST["comment"]):"";
            $acc		=isset($_REQUEST["acc"])?EndcodeStr($_REQUEST["acc"]):"";
            $rate		=isset($_REQUEST["rate"])?EndcodeStr($_REQUEST["rate"]):"";
            $parent		=isset($_REQUEST["parent"])?EndcodeStr($_REQUEST["parent"]):"";
            if($CmModule->updateComment($id,$comment)){
                echo "true";
            }else{
                echo "Error:<br/>".$CmModule->error;
            }
            break;
        case"delete":
            $_type		=isset($_REQUEST["_type"])?$_REQUEST["_type"]:"";
            $id                 =isset($_REQUEST["id"])?$_REQUEST["id"]:"";
            if($CmModule->deleteComment($id)){
                echo "Delete Success.";
                JO_location();
                break;
            }else{
                echo "Error<br/>".$CmModule->error;
            }
            break;
    }    
}
?>